def prime(m):
    x = True
    for k in range(2, int(m ** 0.5)+1):
        if m % k == 0:
            x = False
            break
    return x

b = int(input())
if b < 1000 or b > 9999:
    print(0)
else:
    abcd = str(b)
    fx = 0
    for i in range(len(abcd)):
        for j in range(i+1, len(abcd)+1):
            ifg = int(abcd[i:j])
            if prime(ifg):
                fx = max(fx, ifg)
    print(fx)
